﻿//====================================================================
// Create by Daniel
// file： YCCategory.cs
// project ：YunCMS
// Build time：2012-09-09
// modify:
// description:
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using YunCMS.Model;
using YunCMS.IDAL;

namespace YunCMS.BLL
{
    /// <summary>
    /// Business Logic Layer For YCCategory.
    /// </summary>
    public class YCCategoryBLL
    {

		///<summary>
		/// DAL Instance.
		///</summary>
		public static readonly IYCCategoryDAL dal=DALFactory.CreateYCCategory();
		

		/// <summary>
		/// constructor
		/// </summary>
		public YCCategoryBLL()
		{
		}

		#region Insert update delete
		/// <summary>
		/// insert a YCCategory
		/// </summary>
		/// <param name="model">YCCategory</param>
		/// <returns>The id of the new item</returns>
		public int Add(YCCategory model)
		{
			// Validate input
			if (model == null)
				return 0;
			// Use the dal to insert a new record 
			return dal.Add(model);
		}

		/// <summary>
		/// update a YCCategory.
		/// </summary>
		/// <param name="model">YCCategory</param>
		/// <returns>Rows affected</returns>
		public int Update(YCCategory model)
		{
            // Validate input
			if (model==null)
				return 0;
			// Use the dal to update a new record 
			return dal.Update(model);
		}
				
		/// <summary>
		/// delete a item
		/// </summary>
	    /// <param name="model">id</param>
		/// <returns>affectes rows</returns>
		public int Remove(int id)
		{
			// Validate input
			if(id<0)
				return 0;
			return dal.Delete(id);
		}
				
        /// <summary>
		/// Get a YCCategory 
		/// </summary>
		/// <param name="ID">id</param>
		/// <returns>YCCategory entity</returns>
		public YCCategory GetYCCategory(int id)
		{
			// Validate input
			if(id<0)
				return null;

			// Use the dal to get a record 
			return dal.GetYCCategory(id);
		}
		
		/// <summary>
        /// get YCCategorys by moduleType
        /// if moduleType is empty, select all YCCategorys.
		/// </summary>
		/// <returns>List</returns>
        public IList<YCCategory> GetList(string moduleType)
		{
			// Use the dal to get all records 
            return dal.GetList(moduleType);
		}


        public int UpdateActive(int id, bool value)
        {
            return dal.UpdateOneField(id, "Active", value);
        }
			
		
		/// <summary>
        /// if IsExist a item accroding to id
        /// </summary>
        /// <param name="ID">id</param>
        /// <returns>true/false</returns>
		public bool IsExist(int id)
		{
			return dal.IsExist(id);
		}

        public IList<YCCategory> GetCategoryList(string strwhere)
        {
            return dal.GetCategoryList(strwhere);
        }

        #endregion
		
		
    }
}






